package jmine.tec.security.josso.agent;

import java.security.Principal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.josso.agent.SSOAgentRequest;
import org.josso.agent.http.HttpSSOAgent;
import org.josso.gateway.identity.exceptions.SSOIdentityException;

/**
 * @author takeshi
 */
public class PlainJossoSSOAgent extends HttpSSOAgent {

    private final Log logger = LogFactory.getLog(PlainJossoSSOAgent.class);

    /**
     * {@inheritDoc}
     */
    @Override
    protected Principal authenticate(SSOAgentRequest request) {
        Principal p = null;
        try {
            p = getSSOIdentityManager().findUserInSession(request.getRequester(), request.getSessionId());
        } catch (SSOIdentityException e) {
            logger.error(e.getMessage(), e);
        }
        return p;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void log(String message) {
        logger.info(message);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void log(String message, Throwable throwable) {
        logger.warn(message, throwable);
    }

}
